var experss = require('express');
var router = experss.Router();
var db = require("../public/javascripts/db");
var multer = require('multer');
var upload = multer();
var _ = require("lodash");

/* GET home page. */
router.post('/', upload.array(), function(req, res, next) {
    let demaindid = _.trim(String(req.body.demaindid));
    let solution = _.trim(String(req.body.solution));
    let data = {
        isSuccess: false,
        data: null,
        msg: '需求处理失败！'
    };

    let sql = "UPDATE demand_record SET isfinished=1, finisheddate='" + new Date().toLocaleDateString() +"', solution='" + solution + "' WHERE id=" + demaindid;
    console.log(sql)
    db.execute(sql, function(err, rows) {
        if(err) {
            return res.json(data);
        } else {
            if(rows.affectedRows > 0 ) {
                data.data = rows;
                data.isSuccess = true;
                data.msg = "需求处理成功！";
                return res.json(data);
            } else {
                return res.json(data);
            }
        }
    })
});

module.exports = router;